﻿Imports System
Imports System.Messaging
Imports System.Threading

Module mainModule
    Dim signal As New ManualResetEvent(False)
    Dim count As Integer = 0
    Dim bizDataset As New BizDataSetTableAdapters.bizDataTableAdapter
    Dim dnbDataTable As BizDataSet.bizDataDataTable
    Dim dnbDataRow As BizDataSet.bizDataRow
    Public Sub Main()



        ' Create an instance of MessageQueue. Set its formatter.
        Dim myQueue As New MessageQueue(My.Settings.QueueName.ToString)
        myQueue.Formatter = New XmlMessageFormatter(New Type() _
            {GetType(vDNBData)})

        ' Add an event handler for the ReceiveCompleted event.
        AddHandler myQueue.ReceiveCompleted, AddressOf _
            MyReceiveCompleted

        ' Begin the asynchronous receive operation.
        myQueue.BeginReceive()

        signal.WaitOne()

        ' Do other work on the current thread.

        Return

    End Sub 'Main


    '***************************************************
    ' Provides an event handler for the ReceiveCompleted
    ' event.
    '***************************************************

    Private Sub MyReceiveCompleted(ByVal [source] As _
        [Object], ByVal asyncResult As ReceiveCompletedEventArgs)

        Try
            ' Connect to the queue.
            Dim mq As MessageQueue = CType([source], MessageQueue)

            ' End the asynchronous receive operation.
            Dim m As Message = _
                mq.EndReceive(asyncResult.AsyncResult)

            Dim dnbdatatable As vDNBData = m.Body
            count += 1
            If count = 10 Then
                signal.Set()
            End If

            ' Restart the asynchronous receive operation.
            mq.BeginReceive()

        Catch
            ' Handle sources of MessageQueueException.

            ' Handle other exceptions.

        End Try

        Return

    End Sub 'MyReceiveCompleted

End Module
